/*
 * @Author: 张继伟
 * @Date: 2025-10-29 11:34:15
 * @Description: 
 */
const TOKEN_KEY = 'admin_token';
const USER_INFO_KEY = 'user_info';

export const auth = {
  // 保存 token
  setToken: (token: string) => {
    localStorage.setItem(TOKEN_KEY, token);
  },

  // 获取 token
  getToken: (): string | null => {
    return localStorage.getItem(TOKEN_KEY);
  },

  // 清除 token
  clearToken: () => {
    localStorage.removeItem(TOKEN_KEY);
    localStorage.removeItem(USER_INFO_KEY);
  },

  // 保存用户信息
  setUserInfo: (userInfo: any) => {
    localStorage.setItem(USER_INFO_KEY, JSON.stringify(userInfo));
  },

  // 获取用户信息
  getUserInfo: (): any => {
    const info = localStorage.getItem(USER_INFO_KEY);
    return info ? JSON.parse(info) : null;
  },

  // 检查是否已登录
  isLoggedIn: (): boolean => {
    return !!auth.getToken();
  }
};